<?php
class ArticleController extends CommonController {
    public $data;
    public function __construct()
    {$this->data=include './data.php';
    }

    public function index(){
        $data=$this->data;
        include './view/index.html';
    }
    public function add(){
        if(IS_POST){
            $_POST['time']=date('Y-m-d H:i:s');
            $this->data[]=$_POST;
            $this->datatoFile($this->data);
            $this->redirect('?a=index','上传成功');
        }

        include './view/addShow.html';

    }
    public function edit(){
        $id=$_GET['id'];
        $oldData=$this->data[$id];
        if(IS_POST){
            $_POST['time']=date('Y-m-d H:i:s');
            $this->data[$id]=$_POST;
            $this->dataToFile($this->data);
            $this->redirect('?a=index','编辑成功');
        }
        include './view/editShow.html';
    }
    public function del(){
        $id=$_GET['id'];
        unset($this->data[$id]);
        $this->dataToFile($this->data);
        $this->index();


    }
    public function show(){
        $id=$_GET['id'];
        $nowData=$this->data[$id];
        include './view/show.html';

    }
}